// Retrofit Api Interface implement class,auto generation
package com.demo;

import com.okhttp.retrofit.BaseResponseBodyHandler;
import com.okhttp.retrofit.BaseResponseHandler;
import java.util.concurrent.atomic.AtomicInteger;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;

/**
 *
 * @author GYL
 * @dateTime 20200507 22:46
 * @description  Net:接口封装实现类
 * @see Net
 *
 */
public class NetService {
  private static Net _innerCall;

  /**
   * 生成接口唯一码（WHAT）
   */
  private static final AtomicInteger sNextGeneratedId = new AtomicInteger(10);

  /**
   * 创建Api服务
   */
  private static Net innerCall() {
    if(_innerCall==null){
      _innerCall=com.okhttp.retrofit.RetrofitClient.getInstance().createService(Net.class);
    }
    return _innerCall;
  }

  /**
   * 生成接口唯一码(What)
   */
  private static int generateWhat() {
    for (;;) {
      final int result = sNextGeneratedId.get();
       // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
        int newValue = result + 1;
        if (newValue > 0x00FFFFFF) {
        // Roll over to 1, not 0.
        newValue = 1;
    }
      if (sNextGeneratedId.compareAndSet(result, newValue)) {
      return result;  
    }
    }}

  /**
   *
   * {@link com.demo.Net#doGet1} 
   * @param test 
   * @param data 
   * @param handler  Callback<DataBean> 
   *
   */
  public static int doGet1(String test, DataBean data, Callback<DataBean> handler) {
    int what=generateWhat()+handler.hashCode();
    Call<DataBean> call = innerCall().doGet1(test,data); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet2} 
   * @param test 
   * @param handler  Callback<DataBean> 
   *
   */
  public static int doGet2(String test, Callback<DataBean> handler) {
    int what=generateWhat()+handler.hashCode();
    Call<DataBean> call = innerCall().doGet2(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet3} 
   * @param test 
   * @param handler  Callback<Result<DataBean>> 
   *
   */
  public static int doGet3(String test, Callback<Result<DataBean>> handler) {
    int what=generateWhat()+handler.hashCode();
    Call<Result<DataBean>> call = innerCall().doGet3(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet4} 
   * @param test 
   * @param handler  BaseResponseHandler<T, Result<DataBean>> 
   *
   */
  public static int doGet4(String test, BaseResponseHandler<DataBean, Result<DataBean>> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<Result<DataBean>> call = innerCall().doGet4(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet5} 
   * @param test 
   * @param handler  ResultHandler<DataBean, Result<DataBean>> 
   *
   */
  public static int doGet5(String test, ResultHandler<DataBean, Result<DataBean>> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<Result<DataBean>> call = innerCall().doGet5(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet6} 
   * @param test 
   * @param handler  Callback<ResponseBody> 
   *
   */
  public static int doGet6(String test, Callback<ResponseBody> handler) {
    int what=generateWhat()+handler.hashCode();
    Call<ResponseBody> call = innerCall().doGet6(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet7} 
   * @param test 
   * @param handler  Callback<ResponseBody> 
   *
   */
  public static int doGet7(String test, Callback<ResponseBody> handler) {
    int what=generateWhat()+handler.hashCode();
    Call<ResponseBody> call = innerCall().doGet7(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet8} 
   * @param test 
   * @param handler  BaseResponseBodyHandler<DataBean> 
   *
   */
  public static int doGet8(String test, BaseResponseBodyHandler<DataBean> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<ResponseBody> call = innerCall().doGet8(test); 
    call.enqueue(handler); 
    return  what;
  }

  /**
   *
   * {@link com.demo.Net#doGet9} 
   * @param test 
   * @param handler  ResultHandler<T, Result<DataBean>> 
   *
   */
  public static <T> int doGet9(String test, ResultHandler<T, Result<DataBean>> handler) {
    int what=generateWhat()+handler.hashCode();
    handler.onBeforeExecute(what);
    Call<Result<DataBean>> call = innerCall().doGet9(test); 
    call.enqueue(handler); 
    return  what;
  }
}
